const app = new getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    prompt: '',
    shop_id: 0,
    region_agent: {},
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    let that = this;
    let shop_id = 0;
    if (options.shop_id) {
      shop_id = options.shop_id;
    }

    that.setData({
      shop_id: shop_id
    })
    app.defaultImg();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    let that = this;

    app.restStatus(that, 'listClickFlag');
    app.sendRequest({
      url: 'System.Distribution.regionAgentDetail',
      success: function(res) {
        console.log(res);
        if (res.code == 0) {
          let region_agent = app.checkEmpty(res.data, {});
          that.setData({
            region_agent: region_agent
          })
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 加载基础信息
   */
  loadInfo: function () {
    let that = this;

    app.sendRequest({
      url: "System.Member.memberInfo",
      success: function (res) {
        let code = res.code;
        let data = res.data;

        if (code == 0) {
          let user_info = data.user_info;
          user_info.user_headimg = app.IMG(user_info.user_headimg); //图片路径处理
          that.setData({
            user_info: user_info
          })
        }
      }
    })
  },

  /**
   * 页面跳转
   */
  listClick: function(e) {
    let that = this;
    let url = e.currentTarget.dataset.url;
    let listClickFlag = that.data.listClickFlag;
    if (listClickFlag == 1) {
      return false;
    }
    app.clicked(that, 'listClickFlag');

    wx.navigateTo({
      url: url,
      fail: function(error) {
        console.log('页面跳转失败：' + JSON.stringify(error));
        app.restStatus(that, 'listClickFlag');
      }
    })
  }
})